nice_things/config/Config.sh
The Config class can be used to parse an INI-based config format and retrieve the values of properties from it.
Usage examples
package_conf=#{{{ new Config }}} ./nice_package.conf || exit
if Config_get_string "$package_conf" pkg_version version; then
log_debug "The package version is '${pkg_version}'"
else
log_debug "Config property 'version' not found"
fi
Config
Since 0.3.0 · Source
import "{ Config }" from nice_things/config/Config.sh
SynopsisConfig <&self> <file>
Configuration
–
Description
Constructor for the Config class. Parse the config from the file specified in the <file> parameter and initialize the object with the values of all properties in it.
Usually, this constructor function should be invoked with the new macro, which takes care of creating the <&self> reference to the newly created object.
Options
–
Operands
<&self>: Self reference.<file>: A config file to parse.
Stdin
–
Stdout
–
Exit status
0: Successful completion.12: Invalid self reference<&self>(abort).20: Could not find file at<file>.
Abort
Aborts if self reference <&self> is invalid.
Usage examples
package_conf=#{{{ new Config }}} ./nice_package.conf
Config_destructor
Since 0.3.0 · Source
import "{ Config_destructor }" from nice_things/config/Config_destructor.sh
SynopsisConfig_destructor <&self>
Configuration
–
Description
Clear all data associated with the object.
Options
–
Operands<&self>: Self reference.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.12: Invalid self reference<&self>(abort).
Abort
Aborts if self reference <&self> is invalid.
Usage examples
Config_destructor "$package_conf"
Config_get_array
Since 0.3.0 · Source
import "{ Config_get_array }" from nice_things/config/Config_get_array.sh
SynopsisConfig_get_array <&self> <out_var> [<section>…] <property>
Configuration
–
Description
Get value of a property of type Array. A reference to the object will be assigned to <out_var>.
Options
–
Operands
<&self>: Self reference.<out_var>: Output variable; the result will be written to this variable.<section>: Name of the section, if used.<property>: Name of the property.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.1:<property>not found.12: Invalid self reference<&self>(abort).21: Invalid property type in config. Expected list but found single value.
Abort
- Aborts on invalid or missing arguments.
- Aborts if self reference
<&self>is invalid.
Usage examples
Config_get_array "$package_conf" pkg_authors authors
Config_get_map
Since 0.3.0 · Source
import "{ Config_get_map }" from nice_things/config/Config_get_map.sh
SynopsisConfig_get_map <&self> <out_var> [<section>…] [<property>]
Configuration
–
Description
Get value of a property of type Map. A reference to the object will be assigned to <out_var>.
If the <property> operator is omitted, the entire configuration object will be returned.
Options
–
Operands
<&self>: Self reference.<out_var>: Output variable; the result will be written to this variable.<section>: Name of the section, if used.<property>: Name of the property.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.1:<property>not found.12: Invalid self reference<&self>(abort).21: Invalid property type in config. Expected list but found single value.
Abort
- Aborts on invalid or missing arguments.
- Aborts if self reference
<&self>is invalid.
Usage examples
Config_get_map "$package_conf" log_config module:nice_things/log/log.sh
Config_get_string
Since 0.3.0 · Source
import "{ Config_get_string }" from nice_things/config/Config_get_string.sh
SynopsisConfig_get_string <&self> <out_var> [<section>…] <property>
Configuration
–
Description
Get value of a property of type string. The result will be assigned to <out_var>.
Options
–
Operands
<&self>: Self reference.<out_var>: Output variable; the result will be written to this variable.<section>: Name of the section, if used.<property>: Name of the property.
Stdin
–
Stdout
–
Stderrlog_error.
Exit status
0: Successful completion.1:<property>not found.12: Invalid self reference<&self>(abort).21: Invalid property type in config. Expected single value but found list.
Abort
- Aborts on invalid or missing arguments.
- Aborts if self reference
<&self>is invalid.
Usage examples
Config_get_string "$package_conf" pkg_version version
Config_instance_of
Since 0.3.0 · Source
import "{ Config_instance_of }" from nice_things/config/Config_class.sh
SynopsisConfig_instance_of <&ref>
Configuration
–
Description
Check if <&ref> points to an instance of this class.
Returns status code 0 if <&ref> is a reference to an existing object of this class; otherwise, returns status code 1.
This method will also return status code 1 if <&ref> is not a valid reference, or if the object has already been destroyed.
Options
–
Operands<&ref>: The value to check.
Stdin
–
Stdout
–
Stderr
–
Exit status
0:<&ref>is an instance of this class.1:<&ref>is not an instance of this class.
Abort
–
Usage examples
if ! Config_instance_of "$object"; then
log_warn "The object is not an instance of this class"
fi